package com.example.anitamusicspace.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 小梅就是酱子
 * Date: 2022-08-02
 * Time: 17:10
 */
@Configuration
public class AppConfig implements WebMvcConfigurer {
    @Bean
    public BCryptPasswordEncoder getBCryptPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }

    //添加拦截器，将自定义拦截器加入到系统配置
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
    //1、配置拦截规则
    LoginInterceptor loginInterceptor = new LoginInterceptor();
    registry.addInterceptor(loginInterceptor)
    .addPathPatterns("/**")
    //排除所有的JS
    .excludePathPatterns("/js/**.js")
    //排除images下所有的元素
    .excludePathPatterns("/images/**")
    .excludePathPatterns("/css/**.css")
    .excludePathPatterns("/fronts/**")
    .excludePathPatterns("/player/**")
    .excludePathPatterns("/login.html")
    .excludePathPatterns("/register.html")
    //排除登录接口
    .excludePathPatterns("/user/register")
    .excludePathPatterns("/user/login");

    }

    private void excludePathPatterns(String s) {
    }
}
